package com.kaifamiao.time;

import java.time.LocalDateTime;

/**
 * 1、LocalDateTime 类重写了从 Object 继承的 equals(Object)
 * 2、boolean isBefore( ChronoLocalDateTime<?> other )
 * 3、boolean isAfter( ChronoLocalDateTime<?> other )
 * 4、int compareTo( ChronoLocalDateTime<?> other )
 */
public class CompareLocalDateTime {

    public static void main(String[] args) {
        LocalDateTime first = LocalDateTime.of( 2005, 10, 20, 11, 45, 0 );
        LocalDateTime second = LocalDateTime.of( 2005, 10, 20,11 , 45 , 0 );
        System.out.println( first == second ); // false
        System.out.println( first.equals( second ) ); // true

        System.out.println( "- - - - -" );

        LocalDateTime third = LocalDateTime.of( 2022, 8 , 15, 12 , 30 , 45 );
        System.out.println( first.isBefore( third ) ); // true
        System.out.println( first.isAfter( third ) ); // false

        System.out.println( third.isAfter( first ) ); // true
        System.out.println( third.isBefore( first ) ); // false

        System.out.println( "- - - - -" );

        System.out.println( first.compareTo( third ) ); // 负整数
        System.out.println( first.compareTo( second ) ); // 零
        System.out.println( third.compareTo( first ) ); // 正整数

    }

}
